////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008 Michiel Helvensteijn                                    //
//                                                                            //
// This file is part of the Mist compiler.                                    //
//                                                                            //
// The Mist compiler is free software: you can redistribute it and/or modif   //
// it under the terms of the GNU General Public License as published by       //
// the Free Software Foundation, either version 3 of the License, or          //
// (at your option) any later version.                                        //
//                                                                            //
// The Mist compiler is distributed in the hope that it will be useful,       //
// but WITHOUT ANY WARRANTY; without even the implied warranty of             //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              //
// GNU General Public License for more details.                               //
//                                                                            //
// You should have received a copy of the GNU General Public License          //
// along with the Mist compiler.  If not, see <http://www.gnu.org/licenses/>. //
////////////////////////////////////////////////////////////////////////////////

#ifndef CODELOCATION_HPP
#define CODELOCATION_HPP

/******************************************************************************
 * Includes                                                                   *
 ******************************************************************************/

#include <string>
using std::string;

#include <ostream>
using std::ostream;

#include <boost/operators.hpp>
using boost::partially_ordered;
using boost::equality_comparable;

#include "codeposition.hpp"

namespace yy { class location; }

/******************************************************************************
 * CodeLocation Class                                                         *
 ******************************************************************************/

class CodeLocation : public partially_ordered<CodePosition>, public equality_comparable<CodePosition> {
	public:
		
		CodeLocation();
		CodeLocation(const yy::location& l);
		CodeLocation(const CodePosition& begin, const CodePosition& end);
		CodeLocation(string beginFile, unsigned int beginLine, unsigned int beginColumn, string endFile, unsigned int endLine, unsigned int endColumn);
		CodeLocation(string file, unsigned int beginLine, unsigned int beginColumn, unsigned int endLine, unsigned int endColumn);
		CodeLocation(string file, unsigned int line, unsigned int beginColumn, unsigned int endColumn);
		CodeLocation(string file, unsigned int line, unsigned int column);
		
		CodePosition& begin();
		
		CodePosition& end();
		
		const CodePosition& begin() const;
		
		const CodePosition& end() const;
		
		bool is_in(const CodeLocation& other) const;
		
		ostream& report_to_stream(ostream& stream) const;
		
		bool operator<(const CodeLocation& other) const;
		
		bool operator==(const CodeLocation& other) const;
	
	private:
		
		CodePosition _begin;
		CodePosition _end;
};

/******************************************************************************
 * Output Stream Operator                                                     *
 ******************************************************************************/

ostream& operator<<(ostream& stream, const CodeLocation& loc);

#endif // CODELOCATION_HPP
